import {
  Controller,
  Post,
  Body,
  UseGuards,
  Request,
  Get,
  Delete,
  Put,
  Param,
  Query,
} from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { CreateTokenDto } from './dto/create-token.dto';
import { TokenService } from './token.service';
import { Token } from './token.entity';
import { RemoveTokenDto } from './dto/remove-token.dto';
import { RetrieveTokenDto } from './dto/retrieve-token.dto';
import { UpdateTokenDto } from './dto/update-token.dto';
import { FindTokenDto } from './dto/find-token.dto';
import { JwtAuthGuardUser } from 'src/auth/guards/jwt-auth.guard';

@ApiTags('token')
@Controller('api/token')
export class TokenController {
  constructor(private readonly tokenService: TokenService) {}

  // 增加
  // @UseGuards(JwtAuthGuardUser)
  @Post()
  @ApiOperation({ summary: '增加' })
  async create(@Body() createTokenDto: CreateTokenDto): Promise<Token> {
    return await this.tokenService.create(createTokenDto);
  }

  // 更新
  // @UseGuards(JwtAuthGuardUser)
  @Put(':id')
  @ApiOperation({ summary: '更新' })
  async update(
    @Param() params: RetrieveTokenDto,
    @Body() updateTokenDto: UpdateTokenDto,
  ): Promise<any> {
    return await this.tokenService.update({
      id: params.id,
      updateTokenDto,
    });
  }

  // 列表
  @UseGuards(JwtAuthGuardUser)
  @Get()
  @ApiOperation({ summary: '列表' })
  async findAll(@Query() query: FindTokenDto): Promise<Token> {
    return await this.tokenService.findAll(query);
  }

  // 根据 type 查找
  @Get(':id')
  @ApiOperation({ summary: '根据 type 查找' })
  async findOneById(@Param() params: RetrieveTokenDto): Promise<any> {
    return await this.tokenService.findOneById(params.id);
  }
}
